//
//  BatteryManage.swift
//  Runner
//
//  Created by longxiaobai on 2024/8/4.
//

import Foundation

class BatteryManage {
    let newCount = 2023
    
    static func receiveBatteryLevel(result: FlutterResult) {
        print("---- receiveBatteryLevel is running ----")
        let device = UIDevice.current
        device.isBatteryMonitoringEnabled = true
        if device.batteryState == UIDevice.BatteryState.unknown {
            result(FlutterError(code: "UNAVAILABLE",
                                message: "Battery level not available.",
                                details: nil))
        } else {
            result(Int(device.batteryLevel * 100))
        }
    }
    
    public func getBatteryLevel(result: FlutterResult) {
        print("---- getBatteryLevel \(self.newCount) ----")
        
        let device = UIDevice.current
        device.isBatteryMonitoringEnabled = true
        if device.batteryState == UIDevice.BatteryState.unknown {
            result(FlutterError(code: "UNAVAILABLE",
                                message: "Battery level not available.",
                                details: nil))
        } else {
            result(Int(device.batteryLevel * 100))
        }
    }
}
